package com.example.gss.ServiceImpl;

import com.example.gss.entity.Tutor;
import com.example.gss.mapper.TutorMapper;
import com.example.gss.Service.TutorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

@Service
@Transactional
public class TutorServiceImpl implements TutorService {

    @Autowired
    private TutorMapper tutorMapper;

    @Override
    public Tutor createTutor(Tutor tutor) {
        tutorMapper.insert(tutor);
        return tutor;
    }

    @Override
    public List<Tutor> getAllTutors() {
        return tutorMapper.selectAll();
    }

    @Override
    public Optional<Tutor> getTutorById(String tutorId) {
        return Optional.ofNullable(tutorMapper.selectById(tutorId));
    }

    @Override
    public Optional<Tutor> findByTutorIdAndPassword(String tutorId, String password) {
        return Optional.ofNullable(tutorMapper.selectByTutorIdAndPassword(tutorId, password));
    }

    @Override
    public Tutor updateTutor(Tutor tutor) {
        tutorMapper.update(tutor);
        return tutor;
    }

    @Override
    public void deleteTutor(String tutorId) {
        tutorMapper.delete(tutorId);
    }

    @Override
    public List<Tutor> findTutorsByName(String name) {
        return tutorMapper.selectByName(name);
    }

    @Override
    public List<Tutor> findTutorsByGroupId(String groupId) {
        return tutorMapper.selectByGroupId(groupId);
    }
}    